 var editor='';
 var c = [{
	 src : "images/emjio/shenshou_thumb.gif",
     alt: "[草泥马]"
 }, {
     src : "images/emjio/horse2_thumb.gif",
     alt: "[神马]"
 }, {
     src : "images/emjio/fuyun_thumb.gif",
     alt: "[浮云]"
 }, {
     src : "images/emjio/geili_thumb.gif",
     alt: "[给力]"
 }, {
     src : "images/emjio/wg_thumb.gif",
     alt: "[围观]"
 }, {
     src : "images/emjio/vw_thumb.gif",
     alt: "[威武]"
 }, {
     src : "images/emjio/panda_thumb.gif",
     alt: "[熊猫]"
 }, {
     src : "images/emjio/rabbit_thumb.gif",
     alt: "[兔子]"
 }, {
     src : "images/emjio/otm_thumb.gif",
     alt: "[奥特曼]"
 }, {
     src : "images/emjio/j_thumb.gif",
     alt: "[囧]"
 }, {
     src : "images/emjio/hufen_thumb.gif",
     alt: "[互粉]"
 }, {
     src : "images/emjio/liwu_thumb.gif",
     alt: "[礼物]"
 }, {
     src : "images/emjio/smilea_thumb.gif",
     alt: "[呵呵]"
 }, {
     src : "images/emjio/tootha_thumb.gif",
     alt: "[嘻嘻]"
 }, {
     src : "images/emjio/laugh.gif",
     alt: "[哈哈]"
 }, {
     src : "images/emjio/tza_thumb.gif",
     alt: "[可爱]"
 }, {
     src : "images/emjio/kl_thumb.gif",
     alt: "[可怜]"
 }, {
     src : "images/emjio/kbsa_thumb.gif",
     alt: "[挖鼻屎]"
 }, {
     src : "images/emjio/cj_thumb.gif",
     alt: "[吃惊]"
 }, {
     src : "images/emjio/shamea_thumb.gif",
     alt: "[害羞]"
 }, {
     src : "images/emjio/zy_thumb.gif",
     alt: "[挤眼]"
 }, {
     src : "images/emjio/bz_thumb.gif",
     alt: "[闭嘴]"
 }, {
     src : "images/emjio/bs2_thumb.gif",
     alt: "[鄙视]"
 }, {
     src : "images/emjio/lovea_thumb.gif",
     alt: "[爱你]"
 }, {
     src : "images/emjio/sada_thumb.gif",
     alt: "[泪]"
 }, {
     src : "images/emjio/heia_thumb.gif",
     alt: "[偷笑]"
 }, {
     src : "images/emjio/qq_thumb.gif",
     alt: "[亲亲]"
 }, {
     src : "images/emjio/sb_thumb.gif",
     alt: "[生病]"
 }, {
     src : "images/emjio/mb_thumb.gif",
     alt: "[太开心]"
 }, {
     src : "images/emjio/ldln_thumb.gif",
     alt: "[懒得理你]"
 }, {
     src : "images/emjio/yhh_thumb.gif",
     alt: "[右哼哼]"
 }, {
     src : "images/emjio/zhh_thumb.gif",
     alt: "[左哼哼]"
 }, {
     src : "images/emjio/x_thumb.gif",
     alt: "[嘘]"
 }, {
     src : "images/emjio/cry.gif",
     alt: "[衰]"
 },{
     src : "images/emjio/bba_thumb.gif",
     alt: "[抱抱]"
 }, {
     src : "images/emjio/cza_thumb.gif",
     alt: "[馋嘴]"
 }, {
     src : "images/emjio/88_thumb.gif",
     alt: "[拜拜]"
 }, {
     src : "images/emjio/sk_thumb.gif",
     alt: "[思考]"
 }, {
     src : "images/emjio/sweata_thumb.gif",
     alt: "[汗]"
 },{
     src : "images/emjio/hsa_thumb.gif",
     alt: "[花心]"
 }, {
     src : "images/emjio/gza_thumb.gif",
     alt: "[鼓掌]"
 },{
     src : "images/emjio/hearta_thumb.gif",
     alt: "[心]"
 },{
     src : "images/emjio/ok_thumb.gif",
     alt: "[ok]"
 }, {
     src : "images/emjio/ye_thumb.gif",
     alt: "[耶]"
 }, {
     src : "images/emjio/good_thumb.gif",
     alt: "[good]"
 }, {
     src : "images/emjio/z2_thumb.gif",
     alt: "[赞]"
 }, {
     src : "images/emjio/cake.gif",
     alt: "[蛋糕]"
 }
];
 
 $(function(){
	
	    var avatarUp = new $WebUpload("cover_pic");
	    avatarUp.setUploadBarId("progressBar");
	    avatarUp.init();
	    
	    
	   
	    var E = window.wangEditor;
	    editor = new E('#content');
	    // 隐藏“网络图片”tab
	    editor.customConfig.showLinkImg = false;
	    // 限制一次最多上传 5 张图片
	    editor.customConfig.uploadImgMaxLength = 9;
	    editor.customConfig.uploadFileName = 'file';
	    // 上传图片（举例）
	    editor.customConfig.uploadImgServer =ctp + '/picture/upload';
	    
	    editor.customConfig.emotions = [
	                                    {
	                                        // tab 的标题
	                                        title: '默认',
	                                        // type -> 'emoji' / 'image'
	                                        type: 'image',
	                                        // content -> 数组
	                                        content: c
	                                    }
	                                ]
	    
	    editor.create();
	    
	    getAllClass();
	    getLable();
});
 
 function getLable(){

	 $.ajax({
			type : 'POST',
			dataType:'json', 
			url : ctp + '/interface/labelSearch',
			success:function(data){
				//console.log(JSON.stringify(data.data));
				if(data.code==200){
					var result='<br>';
					for(var i=0;i<data.data.length;i++){
						result+='<span class="badge" onclick="addLable('+data.data[i].label_id+',\''+data.data[i].label_name+'\')" >'+data.data[i].label_name+'</span>' ;
					}
					result+="<span class='badge' onclick='deleteLable()''>删除</span>"
					$('#label_list').html(result);
				}
			},
			error:function(data){
			}
	    });
 }

 function addLable(id,name){
	 $('#label_val').val(name);
	 $('#label').val(id);
 }
 
 function deleteLable (){
	    $('#label_val').val('');
	    $('#label').val('');
	}
 
 

function  getAllClass(){

	 $.ajax({
			type : 'POST',
			dataType:'json', 
			url : ctp + '/interface/classSearch ',
			success:function(data){
				//console.log(JSON.stringify(data.data));
				if(data.code==200){
					var result='';
					for(var i=0;i<data.data.length;i++){
						result+="<option value="+data.data[i].class_id+">"+data.data[i].class_name+"</option>";
					}
					$('#classId').append(result);
				}
			},
			error:function(data){
			}
	    });
}

function addSubmit(){
	 $.ajax({
			type : 'POST',
			dataType:'json', 
			url : ctp + '/interface/topicPublish ',
			data:{
				 class_id:$('#classId').val(),
			     title:$('#title').val(),
			     indroduce:$('#indroduce').val(),
			     content:editor.txt.html(),
			     video_url:$('#video_url').val(),
			     label:$('#label').val(),
			     cover_pic:$('#cover_pic').val(), 
			     source:1
			},
			success:function(data){
				//console.log(JSON.stringify(data.data));
				if(data.code==200){
					swal("提交成功", "", "success");
					window.history.go(-1);
				}else{
					swal("提交失败", "", "error");
				}
			},
			error:function(data){
			}
	    });
}